<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>天气预报小demo</title>
    <!--    引入vue-->
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <!--    引入axios-->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <style type="text/css">
        /*去边框*/
        * {
            margin: 0;
            padding: 0;
            outline: none;
        }

        li {
            list-style: none;
        }

        #app {
            text-align: center;
            margin: auto;
            width: 725px;
        }

        #app h1 {
            font-size: 40px;
            letter-spacing: 20px;
            color: #0669A7;
            font-family: "微软雅黑 Light";
            margin-bottom: 25px;
            outline: none;
        }

        .search {
            font-size: 0px;
        }

        #app input {
            height: 35px;
            width: 450px;
            border: 1px solid #A2BECD;
            font-size: 15px;
        }

        #app button {
            width: 85px;
            height: 37px;
            background-color: #399AD0;
            color: #C3F8FD;
            vertical-align: top;
            border: none;
        }

        .content {
            margin-top: 65px;
        }

        .content .info_type {
            font-size: 30px;
            font-family: "微软雅黑 Light";
            margin: 10px;
            color: #EDB280;
        }

        .content .info_temp {
            font-size: 12px;
            font-family: "微软雅黑 Light";
            margin-top: 10px;
            margin-bottom: 10px;
            color: #EDB280;
        }

        .content .info_data {
            font-size: 11px;
            font-family: "微软雅黑 Light";
            margin-top: 10px;
            color: #C6C6C6;
        }

        .content li {
            width: 130px;
            display: inline-block;
        }

        .divider {
            border-left: 1px solid #DCDCDC;
        }

        .hotkey {
            float: left;
            margin-left: 93px;
        }

        .hotkey a {
            color: #99999C;
            font-size: 15px;
            text-decoration: none;
            margin-right: 20px;
        }
    </style>
</head>
<body>
    <div id="app">
        <h1>天知道</h1>
        <div class="search">
            <input v-model="city" placeholder="请输入要查询的城市">
            <button @click="getWeather" @keyup.enter="getWeather">查 询</button>
        </div>
        <div class="hotkey">
            <a href="#" @click="changeCity('北京')">北京</a>
            <a href="#" @click="changeCity('上海')">上海</a>
            <a href="#" @click="changeCity('广州')">广州</a>
            <a href="#" @click="changeCity('深圳')">深圳</a>
            <span style="clear: left"></span>
        </div>
        <div class="content">
            <ul>
                <li :class="{divider:index != 0}" v-for="(item,index) in weather.forecast">
                    <div class="info_type">{{ item.type }}</div>
                    <div class="info_temp">
                        {{ item.low }}
                        ~
                        {{ item.high }}
                    </div>
                    <div class="info_data">
                        {{ item.date }}
                    </div>
                </li>
            </ul>
        </div>
    </div>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                city: "广州",
                weather: []
            },
            // 钩子函数，在所有DOM实例创建完（但还未渲染）后调用
            created() {
                this.getWeather()
            },
            methods: {
                getWeather: function () {
                    axios.get("http://wthrcdn.etouch.cn/weather_mini?city=" + this.city).then(
                        (response) => {
                            this.weather = response.data.data;
                            console.log(response.data.data);
                        },
                        function (err) {
                            console.log(err);
                        }
                    )
                },
                changeCity: function (city) {
                    this.city = city;
                    this.getWeather();
                }
            }
        })
    </script>
</body>
</html>